#include "./../inc/draw.h"

int toolbar_init()
{
    int * pen    = getBMP_IMG("./res/ui/pen.bmp", 40, 40);
    int * eraser = getBMP_IMG("./res/ui/eraser.bmp", 40, 40);
    int * R      = getBMP_IMG("./res/ui/return.bmp", 40, 40);
    int * back   = getBMP_IMG("./res/ui/back.bmp", 40, 40);

    for(int row = 0; row < 48; row++) {
        for(int col = 0; col < 800; col++) {
            lcd_mmap[row][col] = WHITE;

            // 1. 画笔图标 (位置: 5-45)
            if(row >= 5 && row < 45 && col >= 5 && col < 45) {
                int img_row        = row - 5;
                int img_col        = col - 5;
                lcd_mmap[row][col] = pen[img_row * 40 + img_col];
            }

            // 2. 橡皮图标 (放在画笔右边，位置: 55-95)
            else if(row >= 5 && row < 45 && col >= 55 && col < 95) {
                if(col >= 55 && col < 95) {
                    int img_row        = row - 5;
                    int img_col        = col - 55;
                    lcd_mmap[row][col] = eraser[img_row * 40 + img_col];
                }
            }

            // 3. 四个圆 (整体右移100像素：原位置+100)
            // 半径为5的圆 (原55-95 → 155-195)
            else if(row >= 5 && row < 45 && col >= 155 && col < 195) {
                int center_x = 155 + 20;
                int center_y = 5 + 20;
                int dx       = col - center_x;
                int dy       = row - center_y;
                if(dx * dx + dy * dy <= 5 * 5) {
                    lcd_mmap[row][col] = BLACK;
                }
            }
            // 半径为10的圆 (原105-145 → 205-245)
            else if(row >= 5 && row < 45 && col >= 205 && col < 245) {
                int center_x = 205 + 20;
                int center_y = 5 + 20;
                int dx       = col - center_x;
                int dy       = row - center_y;
                if(dx * dx + dy * dy <= 10 * 10) {
                    lcd_mmap[row][col] = BLACK;
                }
            }
            // 半径为15的圆 (原155-195 → 255-295)
            else if(row >= 5 && row < 45 && col >= 255 && col < 295) {
                int center_x = 255 + 20;
                int center_y = 5 + 20;
                int dx       = col - center_x;
                int dy       = row - center_y;
                if(dx * dx + dy * dy <= 15 * 15) {
                    lcd_mmap[row][col] = BLACK;
                }
            }
            // 半径为20的圆 (原205-245 → 305-345)
            else if(row >= 5 && row < 45 && col >= 305 && col < 345) {
                int center_x = 305 + 20;
                int center_y = 5 + 20;
                int dx       = col - center_x;
                int dy       = row - center_y;
                if(dx * dx + dy * dy <= 20 * 20) {
                    lcd_mmap[row][col] = BLACK;
                }
            }

            // 4. 颜色方块 (整体右移100像素)
            // 黄色正方形 (原255-305 → 355-405)
            else if(row >= 10 && row < 40 && col >= 355 && col < 405) {
                if(col >= 360 && col < 390) {
                    lcd_mmap[row][col] = YELLOW;
                }
            }
            // 红色正方形 (原305-355 → 405-455)
            else if(row >= 10 && row < 40 && col >= 405 && col < 455) {
                if(col >= 410 && col < 440) {
                    lcd_mmap[row][col] = RED;
                }
            }
            // 绿色正方形 (原355-405 → 455-505)
            else if(row >= 10 && row < 40 && col >= 455 && col < 505) {
                if(col >= 460 && col < 490) {
                    lcd_mmap[row][col] = GREEN;
                }
            }
            // 蓝色正方形 (原405-455 → 505-555)
            else if(row >= 10 && row < 40 && col >= 505 && col < 555) {
                if(col >= 510 && col < 540) {
                    lcd_mmap[row][col] = BLUE;
                }
            }

            // 5. 重置按钮
            else if(row >= 5 && row < 45 && col >= 555 && col < 605) {
                if(col >= 560 && col < 600) {
                    int img_row        = row - 5;
                    int img_col        = col - 560;
                    lcd_mmap[row][col] = R[img_row * 40 + img_col];
                }
            }

            // 5. 返回按钮 (位置保持不变: 750-800)
            else if(row >= 5 && row < 45 && col >= 750 && col < 800) {
                if(col >= 755 && col < 795) {
                    int img_row        = row - 5;
                    int img_col        = col - 755;
                    lcd_mmap[row][col] = back[img_row * 40 + img_col];
                }
            }
        }
    }
    free(R);
    free(pen);
    free(eraser);
    return 0;
}